package com.derbysoft.dswitch.adapter.ihg.dswitch3.translate.impl;

import com.derbysoft.dswitch.adapter.ihg.dswitch3.translate.Translator;
import com.derbysoft.dswitch.dto.hotel.reservation.HotelReservationRS;
import com.derbysoft.dswitch.remote.hotel.dto.HotelAvailResponse;
import com.derbysoft.dswitch.remote.hotel.dto.HotelReservationRequest;
import com.derbysoft.dswitch.remote.hotel.dto.HotelReservationResponse;
import org.springframework.stereotype.Component;

/**
 * Created by: jason
 * Date: 2012-05-14
 */
@Component("hotelPreviewRSTranslator")
public class HotelPreviewRSTranslatorImpl extends BaseTranslator
        implements Translator<HotelAvailResponse, HotelReservationResponse, HotelReservationRequest> {

    @Override
    public HotelReservationResponse translate(HotelAvailResponse hotelAvailResponse,
                                              HotelReservationRequest reservationRequest) {
        HotelReservationResponse hotelReservationResponse = new HotelReservationResponse();
        hotelReservationResponse.setTaskId(reservationRequest.getHeader().getTaskId());
        hotelReservationResponse.setHotelReservationRS(createHotelReservationRS(hotelAvailResponse, reservationRequest));
        return hotelReservationResponse;
    }

    private HotelReservationRS createHotelReservationRS(HotelAvailResponse hotelAvailResponse, HotelReservationRequest reservationRequest) {
        HotelReservationRS hotelReservationRS = new HotelReservationRS();
        hotelReservationRS.setCancelPolicy(findCancelPolicy(hotelAvailResponse, reservationRequest));
        hotelReservationRS.setHotelReservation(reservationRequest.getHotelReservationRQ().getHotelReservation());
        setRateInfo(hotelReservationRS, hotelAvailResponse, reservationRequest);
        hotelReservationRS.setErsp(reservationRequest.getHotelReservationRQ().getErsp());
        return hotelReservationRS;
    }
}
